package edu.pku.sei.autounit.util;

import java.util.HashSet;
import java.util.Set;

public class NameFactory {
	final static public int PARAMETER = 0;
	final static public int RUNOBJECT = 1;
	final static public int TESTCASE = 2;
	final static public int KEY = 3;
	final static public int VALUE = 4;
	final static public int ELEMENT = 5;
	final static public int TEMP = 6;

	private Set<String> set;
 
	public NameFactory() {
		set = new HashSet<String>();
	}

	public String getName(String seed, int type) {
		String prefix = null;
		if (type == PARAMETER)
			prefix = "param" ;
		else if(type == RUNOBJECT)
			prefix = "obj";
		else if(type == TESTCASE){
			prefix = seed;
			prefix = Character.toUpperCase(prefix.charAt(0))
				+ prefix.substring(1,prefix.length());
			prefix = "test"+prefix;
		}
		else if(type == KEY)
			prefix = "key";
		else if(type == VALUE)
			prefix = "value";
		else if(type == ELEMENT)
			prefix = "e";
		else
			prefix = "temp";
		String temp = prefix;
		if (!set.contains(temp)) {
			set.add(temp);
			return temp;
		}
		for (int i = 1;; i++) {
			temp = prefix+i;
			if (!set.contains(temp)) {
				set.add(temp);
				return temp;
			}
		}
	}
}
